package core;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;

public class Output {
    
    public static boolean debug = false;
    private static PrintStream write;
    
    private Output() {
        try {
            write = new PrintStream(new File("log.txt"));
        }catch(FileNotFoundException e) {
            System.out.println("file log tidak bisa dibuat");
        }
    }
    
    public void print(String text) {
        write.print(text);  
        if(debug)
            System.out.print(text);
    }
    
    public void print(int val) {
        write.print(val);
        if(debug)
            System.out.print(val);
    }
    
    public void print(char c) {
        write.print(c);        
        if(debug)
            System.out.print(c);
    }
    
    public void print(int[] individu) {
        for(int i=0;i<individu.length;i++) {
            write.print(individu[i] +" ");
            if(debug)
                System.out.print(individu[i] + " ");
        }
    }
    
    public void println(String text) {
        write.println(text);
        if(debug)
            System.out.println(text);
    }
    
    public void println(int val) {
        write.println(val);
        if(debug)
            System.out.println(val);
    }
    
    public void println(char c) {
        write.println(c);
        if(debug)
            System.out.println(c);
    }       
    
    public void println(int[] individu) {
        for(int i=0;i<individu.length;i++) {
            write.print(individu[i] +" ");
            if(debug)
                System.out.print(individu[i] + " ");
        }
        write.println("");
        if(debug)
            System.out.println("");
    }
        
    public static Output getInstance() {
        return OutputHolder.INSTANCE;        
    }
    
    private static class OutputHolder {
        private static final Output INSTANCE = new Output();
    }
}
